﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace 水费管理系统
{
    public partial class Form_Main : Form
    {
        DataSet1.用户Row user;
        DataSet1.设置年月Row 年月;
        public Form_Main()
        {
            InitializeComponent();
        }

        private void toolStripContainer1_ContentPanel_Load(object sender, EventArgs e)
        {

        }

        private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult ReturnDlg = MessageBox.Show(this, "确定退出应用程序吗?", "信息提示",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            switch (ReturnDlg)
            {
                case DialogResult.Yes:
                    if(this.dataSet1.HasChanges())
                        this.dataSet1.AcceptChanges(); 
                    break;
                case DialogResult.No:
                    e.Cancel=true;
                    break;
            }		
        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox aboutbox = new AboutBox();
            aboutbox.ShowDialog();
        }

        private void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void Form_Main_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dataSet1.基本信息”中。您可以根据需要移动或移除它。
            //this.基本信息TableAdapter.Fill(this.dataSet1.基本信息);
            Form_login form_login = new Form_login();
            DialogResult dr=form_login.ShowDialog();
            if (dr == DialogResult.Cancel)
            {                
                this.Close();
                return;
            }
            user = form_login.user;
            TSLuser.Text = "当前用户:"+user.用户名;

            this.设置年月TableAdapter1.FillByYx(this.dataSet1.设置年月);
            年月 = this.dataSet1.设置年月[0];
            TSL年月.Text = "当前年月:" + 年月.年度 + "年" + 年月.月份 + "月";


            if (user.超级管理员) return;
            用户ToolStripMenuItem.Enabled = false;
            抄表ToolStripMenuItem.Enabled = false;
            收费ToolStripMenuItem.Enabled = false;
            管理ToolStripMenuItem.Enabled = false;
            if (user.抄表员权限) 
            {
                抄表ToolStripMenuItem.Enabled = true;
            }
            if (user.管理员权限)
            {
                用户ToolStripMenuItem.Enabled = true;
                管理ToolStripMenuItem.Enabled = true;
            }
            if (user.收费员权限)
            {
                收费ToolStripMenuItem.Enabled = true;
            }

            form_login.Dispose();

        }

        private void 录入ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            抄表录入 cblr = new 抄表录入();
            cblr.ShowDialog();
            cblr.Dispose();
        }

        private void 收费录入ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            收费录入 sflr = new 收费录入();
            sflr.ShowDialog();
            sflr.Dispose();
        }

        private void 管理员管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            管理员管理 glygl = new 管理员管理();
            glygl.ShowDialog();
            glygl.Dispose();
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            用户单位管理 sjsz = new 用户单位管理();
            sjsz.ShowDialog();
            sjsz.Dispose();
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            设置年月 szny = new 设置年月();
            szny.ShowDialog();
            this.设置年月TableAdapter1.FillByYx(this.dataSet1.设置年月);
            年月 = this.dataSet1.设置年月[0];
            TSL年月.Text = "当前年月:"+年月.年度 + "年" + 年月.月份 + "月";
            szny.Dispose();
        }

        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            用水单位管理 ysdwgl = new 用水单位管理();
            ysdwgl.ShowDialog();
            ysdwgl.Dispose();
        }

        private void 查询统计ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            统计分析 tjfx = new 统计分析();
            tjfx.ShowDialog();
            tjfx.Dispose();            
        }

        private void 登记ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //基本情况 jbqk = new 基本情况();
            //jbqk.ShowDialog();
            //jbqk.Dispose();
            //开户 kh=new 开户();
            //panel1.Controls.Clear();
            //panel1.Controls.Add(kh);
            //kh.Dock = DockStyle.Fill;
            登记 dj = new 登记();
            dj.ShowDialog();
            dj.Dispose();
        }

        private void 查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            水表查询 sbcx = new 水表查询();
            sbcx.ShowDialog();
            sbcx.Dispose();
        }

        private void 查询ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            抄表查询 cbcx = new 抄表查询();
            cbcx.ShowDialog();
            cbcx.Dispose();
        }

        private void 收费查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            收费查询 sfcx = new 收费查询();
            sfcx.ShowDialog();
            sfcx.Dispose();
        }

        private void 更换背景button_Click(object sender, EventArgs e)
        {
            if(openFileDialog1.ShowDialog()==DialogResult.OK)
                panel1.BackgroundImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);
        }
    }
}